package utils.version5;


import java.lang.reflect.Proxy;

public class TxProxyFactory {
    private boolean enableTransaction = false;//模拟时候添加了事务切面

    private TransactionManager transactionManager;

    public TransactionManager getTransactionManager() {
        return transactionManager;
    }

    public void setTransactionManager(TransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }

    public boolean isEnableTransaction() {
        return enableTransaction;
    }

    public void setEnableTransaction(boolean enableTransaction) {
        this.enableTransaction = enableTransaction;
    }


    public  Object getBean(Object target) {
        if(enableTransaction == true ) {
            return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                                            target.getClass().getInterfaces(),
                                            new TxInvocationHandler(target,transactionManager));
        }
        return target;
    }
}

